package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCVehicleBreakdown.VehicleBreakdown;

public class BreakdownAdditionDto {

    private int breakdownSPNValue;
    private int breakdownFMIValue;
    private int spnChangeMode;
    private int faultsCount;
    private int faultType;

    public int getBreakdownSPNValue() {
        return breakdownSPNValue;
    }
    public void setBreakdownSPNValue(int breakdownSPNValue) {
        this.breakdownSPNValue = breakdownSPNValue;
    }
    public int getBreakdownFMIValue() {
        return breakdownFMIValue;
    }
    public void setBreakdownFMIValue(int breakdownFMIValue) {
        this.breakdownFMIValue = breakdownFMIValue;
    }
    public int getSpnChangeMode() {
        return spnChangeMode;
    }
    public void setSpnChangeMode(int spnChangeMode) {
        this.spnChangeMode = spnChangeMode;
    }
    public int getFaultsCount() {
        return faultsCount;
    }
    public void setFaultsCount(int faultsCount) {
        this.faultsCount = faultsCount;
    }
    public int getFaultType() {
        return faultType;
    }
    public void setFaultType(int faultType) {
        this.faultType = faultType;
    }

    public static BreakdownAdditionDto parseProto(VehicleBreakdown vehicleBreakdown){
        BreakdownAdditionDto breakdownAdditionDto = new BreakdownAdditionDto();
        breakdownAdditionDto.setBreakdownFMIValue(vehicleBreakdown.getBreakdownFMIValue());
        breakdownAdditionDto.setBreakdownSPNValue(vehicleBreakdown.getBreakdownSPNValue());
        breakdownAdditionDto.setFaultsCount(vehicleBreakdown.getFaultsCount());
        breakdownAdditionDto.setFaultType(vehicleBreakdown.getFaultType());
        breakdownAdditionDto.setSpnChangeMode(vehicleBreakdown.getSpnChangeMode());
        return breakdownAdditionDto;
    }

    /**
     * 解析成String拼接字符串
     * @param vehicleBreakdown
     * @return
     */
    public static String parseString(VehicleBreakdown vehicleBreakdown){
        return EntityConvert.convert(
                vehicleBreakdown.getBreakdownFMIValue(),
                vehicleBreakdown.getBreakdownSPNValue(),
                vehicleBreakdown.getFaultsCount(),
                vehicleBreakdown.getFaultType(),
                vehicleBreakdown.getSpnChangeMode());
    }

    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static VehicleBreakdown parsePB(String str){
        VehicleBreakdown.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=5){
                builder = VehicleBreakdown.newBuilder();
                builder.setBreakdownFMIValue(Integer.valueOf(revert[0]));
                builder.setBreakdownSPNValue(Integer.valueOf(revert[1]));
                builder.setFaultsCount(Integer.valueOf(revert[2]));
                builder.setFaultType(Integer.valueOf(revert[3]));
                builder.setSpnChangeMode(Integer.valueOf(revert[4]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
